using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Fulan.OutlookSyn
{
    public class FolderControl
    {
        public static readonly string workFolderName="FarlandOutlookSyn";

        private string workFolder;
        private System.IO.DirectoryInfo dir;
        public FolderControl()
        {
            this.workFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)+"\\"+
                FolderControl.workFolderName;
            this.CheckWorkFolder();
        }

        private void CheckWorkFolder()
        {
            this.dir = new System.IO.DirectoryInfo(this.workFolder);
            if (!dir.Exists)
                dir.Create();            
        }

        public string WorkFolder
        {
            get { return this.workFolder; }
        }

        public FileInfo[] Files
        {
            get
            {
                return this.dir.GetFiles();
            }
        }
        
        
        public static void ClearingCSV()
        {
            Random rad = new Random(10);
            if (rad.Next() > 5)
                return;
            
            FolderControl folder = new FolderControl();
            DirectoryInfo dir = new DirectoryInfo(folder.WorkFolder);
            FileInfo[] files= dir.GetFiles("*.csv");
            foreach(FileInfo info in files)
            {
                try
                {
                    info.Delete();
                }catch
                {
                }
            }
        }
    }
}
